package com.dsl.utils;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;

/**
 * @Description cookie工具类，方便获取cookie复用
 * @Author dsl
 * @Date 2024/9/6 下午10:06
 * @Version 1.0
 */
public class CookieUtil {

    public static String getValue(HttpServletRequest request, String name) {
        if(request == null || name == null){
            throw new IllegalArgumentException("参数为空！");
        }

        Cookie[] cookies = request.getCookies();
        if(cookies != null){
            for(Cookie cookie : cookies){
                if(cookie.getName().equals(name)){
                    return cookie.getValue();
                }
            }
        }
        return null;
    }
}
